<div class="span3">
    <div class="well sidebar-nav">
    <ul class="nav nav-list">
        <li class="nav-header">CHUYÊN MỤC</li>
        <li<?php if (!$this->current_category){ ?> class="active"<?php } ?>><a href="<?php echo $this->config->base_path; ?>/reader/book">Tất cả</a></li>
        <?php foreach($this->categories as $category) { ?>
        <li<?php if ($category['CategoryID'] == $this->current_category){ ?> class="active"<?php } ?>><a href="<?php echo $this->config->base_path; ?>/reader/book/index/category_id/<?php echo $category['CategoryID']; ?>"><?php echo $category['Name']; ?></a></li>
        <?php } ?>                
    </ul>
    </div><!--/.well -->
</div>
<div class="span8">
    <fieldset>
            <legend></legend>
            <form class="well form-search">
            <div class="right">
                <input type="text" name="q" value="<?php echo $this->q; ?>" class="input-medium search-query">
                <button type="submit" class="btn">Tìm kiếm</button>
            </div>
        </form>
        <?php if ($this->q) { ?>
        <div class="alert alert-info">Có <strong><?php echo count($this->books); ?></strong> kết quả tìm kiếm với từ khoá: "<strong><?php echo $this->q; ?></strong>"</div>
        <?php } ?>
            <table class="table table-striped">
            <tr>        
                <th>Tên sách</th>
                <th>Tác giả</th>
                <th>Chuyên mục</th>
                <th>Nhà xuất bản</th>                
            </tr>
            <?php foreach($this->books as $book) { ?>
            <tr id="row-book-id-<?php echo $book['BookID']; ?>">
                <td><a href="javascript:;" onclick="$('#book-detail-<?php echo $book['BookID']; ?>').modal()"><?php echo $book['Title']; ?></a></td>
                <td><?php echo $book['Author']; ?></td>
                <td><?php echo $book['Category']; ?></td>
                <td><?php echo $book['Publisher']; ?></td>                                                                  
                <div class="modal hide" id="book-detail-<?php echo $book['BookID']; ?>">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal">×</button>
                        <h3><?php echo $book['Title']; ?></h3>
                    </div>
                    <div class="modal-body">
                        <div class="span2"><img src="<?php echo $this->config->static_path . '/uploads/covers/thumb/' . $book['CoverPath']; ?>" /></div>
                        <div class="span10">
                            <ul>
                                <li><strong>Tên sách:</strong> <?php echo $book['Title']; ?></li>
                                <li><strong>Chuyên mục:</strong> <?php echo $book['Category']; ?></li>
                                <li><strong>Nhà xuất bản:</strong> <?php echo $book['Publisher']; ?></li>
                                <?php if ($book['InStock'] > 0){ ?>
                                <li><strong>Trạng thái:</strong> <span class="label label-success">Có thể mượn</span></li>
                                <?php } else { ?>
                                <li><strong>Trạng thái:</strong> <span class="label label-important">Đã mượn hết</span></li>
                                <?php } ?>
                            </ul>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button onclick="Book.borrow(<?php echo $book['BookID']; ?>)" class="btn btn-primary"<?php if ($book['InStock'] < 1){ ?> disabled<?php }?>>Đặt mượn</button>
                        <a href="javascript:;" class="btn" data-dismiss="modal">Đóng</a>                        
                    </div>
                </div>
            </tr>
            <?php } ?>
        </table>
        <?php echo $this->pagination; ?>
    </fieldset>
</div>
<script type="text/javascript">
    var Book = {
        'borrow' : function(BookID){		
            $.ajax({
                url: config.base_path + '/reader/book/borrow',
                type: 'post',
                data: {
                    BookID: BookID
                },
                dataType: 'json',					
                success: function(res){
                    if (res.status == 0)
                    {
                        $('#book-detail-' + BookID).modal('hide');
                        Utils.Message.Error(res.message);
                    }
                    else
                    {
                        $('#book-detail-' + BookID).modal('hide');
                        Utils.Message.Success(res.message);          
                        setTimeout(function(){
                            window.location.reload();
                        }, 3000);
                    }                   
                }
            });
        }
    };
</script>